home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2497 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. Path: comsearch.com!tnasca
  2. From: Thuan Nguyen <thnguyen@comsearch.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: storing address of member functions, HELP!
  5. Date: 17 Jan 1996 22:43:55 GMT
  6. Organization: ComSearch, Inc
  7. Message-ID: <4dju3b$ehi@gateway.comsearch.com>
  8. References: <4djbj4$5nu@news-rocq.inria.fr>
  9. NNTP-Posting-Host: arcturus.comsearch.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (X11; I; SunOS 4.1.4 sun4c)
  14. X-URL: news:4djbj4$5nu@news-rocq.inria.fr
  15.  
  16. Sophie.Cluet@inria.fr (Sophie Cluet) wrote:
  17. >Hello,
  18. >
  19. >I have a graph whose nodes represent operations and 
  20. >whose edges indicate the operations parameters.
  21. >Each operation stores the address of its evaluation 
  22. >function which is invoked through a function called
  23. >"evaluate" which simply evaluate the operation parameters
  24. >and invoke the code.
  25. >
  26. >For instance, I have:
  27. >  Class nary_op 
  28. >    {...
  29. >     op ** parameters;      // the edges
  30. >     int parameters_nb;
  31. >     ...
  32. >     int evaluate();    // evaluate the parameters and invoke
  33. >                        // the below stored function (code)
  34. >     int (nary_op::*code)();  // address of the evaluation function
  35. >     ...
  36. >     int build_list(); // one such evaluation fonction 
  37. >     int and();        // another evaluation function
  38. >     ...}
  39. >
  40. >The classes are organised in a hierarchy.
  41. >For instance, 
  42. >  Class struct_op: public nary_op
  43. >    {char ** names;  // added stored information
  44. >     ...
  45. >     int build_struct();  // an evaluation function 
  46. >                          // that uses the above names
  47. >     ...}
  48. >
  49. >      
  50. >Now, the problem. The compiler accepts neither of the following 
  51. >instructions on a nary_op:
  52. >    
  53. >     code=&struct_op::build_struct;
  54. >  or
  55. >     code=(int (nary_op::*)())&struct_op::build_struct;
  56. >
  57. >According to the C++ book I have, this assignment
  58. >not beeing type-safe is forbidden. I aggree on the
  59. >fact that it is not type safe, but I don't know of any
  60. >casting that is. 
  61. >
  62. >Do you have any idea to help me out?
  63. >
  64. >Of course, I do not want to duplicate "code" or the 
  65. >"int evaluate()" function. Also, I'd rather have as
  66. >little late-binding as possible when evaluating my
  67. >operations graph.
  68. >
  69. >Thanks in advance,
  70. >Sophie.
  71.  
  72. Let's me try. The scope of the function is the same as the scope of the object
  73. itself. In code = &struct_op::build_struct; the object doesnt exist.
  74. How about declaring the build_struct function static.
  75.  
  76. Hope this help
  77.  
  78.